package com.feeyo.groundservice.composewidget.usage

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.blankj.utilcode.util.ToastUtils
import com.feeyo.groundservice.composewidget.R
import com.feeyo.groundservice.composewidget.constant.NumberType
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.composewidget.util.dimenToDp
import com.feeyo.groundservice.composewidget.util.intervalClick
import com.feeyo.groundservice.composewidget.util.toComposeColor
import com.feeyo.groundservice.composewidget.view.edit.RoundedCornerOutlinedTextField
import com.feeyo.groundservice.composewidget.view.edit.RoundedCornerOutlinedTextFieldValue
import com.feeyo.groundservice.composewidget.view.edit.RoundedCornerTextField
import com.feeyo.groundservice.composewidget.view.util.VerticalSpace

/**
 *作者：QLH on 2024-09-18
 *描述：
 */
class TextFieldActivity : BaseComposeActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Init()
        }
    }


    @Composable
    private fun Init() {
        Column(
            modifier = Modifier.padding(horizontal = 10.dp)
        ) {
            RoundTextFieldSample()
            VerticalSpace(20.dp)
            RoundOutlinedTextFieldSample()
            VerticalSpace(20.dp)
            RoundOutlinedTextFieldPwd()
            VerticalSpace(20.dp)
            RoundOutlinedTextFieldValue()
            VerticalSpace(20.dp)
            EndExtensionRoundTextFieldSample()
        }
    }
}

@Composable
private fun RoundTextFieldSample() {

    RoundedCornerTextField(
        onValueChange = {

        },
        hint = "请输入内容",
        hasLeadingIcon = true,
        hasTrailingIcon = true,
        errorAnimation =  true,
        focusedTextColor = R.color.black_33.toComposeColor(),
        cursorColor = R.color.blue_2E76EE.toComposeColor(),
        focusedLeadingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedTrailingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedContainerColor = R.color.green_1FBB7D.toComposeColor(),
        focusedPwdIconColor = R.color.green_1FBB7D.toComposeColor(),
        hasPwdIcon = true,
        imeAction = ImeAction.Send,
        keyboardType = KeyboardType.Number,
        decimalPlaces = 2,
        numberType = NumberType.Negative,
        keyboardActions = {
            ToastUtils.showShort("发送")
        },
        rightAlignment = true,
    )
}

@Composable
private fun RoundOutlinedTextFieldSample() {

    RoundedCornerOutlinedTextField(
        onValueChange = {

        },
        hint = "请输入内容",
        hasLeadingIcon = true,
        hasTrailingIcon = true,
        focusedTextColor = R.color.red_EB5451.toComposeColor(),
        cursorColor = R.color.blue_2E76EE.toComposeColor(),
        focusedLeadingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedTrailingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedPwdIconColor = R.color.green_1FBB7D.toComposeColor(),
        hasPwdIcon = true,
        imeAction = ImeAction.Search,
        keyboardActions = {
            ToastUtils.showShort("搜索")
        },
        closeKeyBoard = {}
    )
}

@Composable
private fun RoundOutlinedTextFieldPwd() {

    RoundedCornerOutlinedTextField(
        onValueChange = {

        },
        hint = "请输入密码",
        hasLeadingIcon = true,
        hasTrailingIcon = true,
        focusedTextColor = R.color.red_EB5451.toComposeColor(),
        cursorColor = R.color.blue_2E76EE.toComposeColor(),
        focusedLeadingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedTrailingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedPwdIconColor = R.color.green_1FBB7D.toComposeColor(),
        hasPwdIcon = true,
        closeKeyBoard = {}
    )
}


@Composable
private fun RoundOutlinedTextFieldValue() {

    RoundedCornerOutlinedTextFieldValue(
        onValueChange = {

        },
        content = "测试光标位置的",
        hint = "请输入密码",
        hasLeadingIcon = true,
        hasTrailingIcon = true,
        focusedTextColor = R.color.red_EB5451.toComposeColor(),
        cursorColor = R.color.blue_2E76EE.toComposeColor(),
        focusedLeadingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedTrailingIconColor = R.color.blue_2E76EE.toComposeColor(),
        hasPwdIcon = true,
        closeKeyBoard = {}
    )
}


@Composable
private fun EndExtensionRoundTextFieldSample() {

    RoundedCornerTextField(
        onValueChange = {

        },
        hint = "请输入内容",
        hasLeadingIcon = true,
        hasTrailingIcon = true,
        focusedTextColor = R.color.red_EB5451.toComposeColor(),
        cursorColor = R.color.blue_2E76EE.toComposeColor(),
        focusedLeadingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedTrailingIconColor = R.color.blue_2E76EE.toComposeColor(),
        focusedPwdIconColor = R.color.green_1FBB7D.toComposeColor(),
        hasPwdIcon = true,
        endExtensionView = {
            Box(
                modifier = Modifier.intervalClick {
                    ToastUtils.showShort("点击了")
                }
            ) {
                Text(
                    text = "自定义尾部"
                )
            }
        }
    )
}